package com.builder.settings;

import com.builder.settings.interfaces.HelperStorage;
import com.gooddies.utils.KeyValue;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 * @author sad
 */
public class PropertyCellRenderer extends DefaultTableCellRenderer {

    private final HelperStorage helperStorage;

    public PropertyCellRenderer(HelperStorage helperStorage) {
        this.helperStorage = helperStorage;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        PropertiesTableModel model = (PropertiesTableModel) table.getModel();
        KeyValue<String, String> v = model.getRow(row);
        if (helperStorage.contains(v.getKey())) {
            label.setForeground(Color.BLACK);
        } else {
            label.setForeground(Color.GRAY);
        }

        return label;
    }
}
